#include <stdio.h>
#include "ofc/DDirectory.h"

int main(int argc, char *argvp[])
{
  DDirectory    *dir1;
  DList         *subs;
  DListIterator *iter = [DListIterator new];
  DText          *str;

  if ([DDirectory create :"sub"])      // Create a directory
    printf("Directory \"sub\" succesfully created.\n");
  else
    printf("Directory \"sub\" could not be created:%d.\n", [DDirectory error]);

  if ([DDirectory exist :"sub"])       // Check for directory
    printf("Directory \"sub\" exists.\n");
  else
    printf("Directory \"sub\" does noet exist:%d.\n", [DDirectory error]);

  if ([DDirectory move :"sub" :"renamed"])  // Rename directory
    printf("Directory \"sub\" renamed to \"renamed\".\n");
  else
    printf("Directory \"sub\" could not be renamed to \"renamed\":%d.\n", [DDirectory error]);

  if ([DDirectory remove :"renamed"])   // Remove directory
    printf("Directory \"renamed\" removed.\n");
  else
    printf("Directory \"renamed\" cound not be \"renamed\":%d.\n", [DDirectory error]);


  dir1 = [DDirectory current];         // Get the current directory

  if ([dir1 parent])
    printf("Move to parent succesfull:%s.\n", [dir1 path]);
  else
    printf("Move to parent failed.\n");

  subs = [DDirectory childs :[dir1 path] :nil]; // Iterate all sub directories

  if (subs != nil)
  {
    printf("Sub directories (%ld):\n", [subs length]);

    [iter list :subs];

    str = [iter first];
    while (str != nil)
    {
      printf("  %s\n", [str cstring]);
      str = [iter next];
    }
    [iter free];                         // Cleanup iter and list
    [subs free];
  }
  else
    printf("No subdirectories in the parent directory ?!\n");

  [dir1 free];                         // Cleanup directory

  return 0;
}

